﻿CREATE FUNCTION [dbo].[InitCaps](
	@Phrase varchar(4000)
)RETURNS nvarchar(4000)
AS BEGIN

SET @Phrase = '<w>'+REPLACE(@Phrase,' ','</w><w>')+'</w>'
DECLARE @Xml xml
SET @Xml = @Phrase

DECLARE @W TABLE(w nvarchar(512))
INSERT INTO @W
SELECT T.c.value('.','varchar(400)') FROM @Xml.nodes('w') T(c)

DECLARE @Out nvarchar(4000)
SET @Out =(SELECT dbo.InitCap(w)+' '  FROM @W FOR XML PATH(''))
RETURN LEFT(@Out,LEN(@Out))
END
